home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / BUTTON.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  199 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.9  $
  6. //
  7. // Definition of class TButton. This defines the basic behavior of all buttons.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_BUTTON_H)
  10. #define OWL_BUTTON_H
  11.  
  12. #if !defined(OWL_CONTROL_H)
  13. # include <owl/control.h>
  14. #endif
  15.  
  16. #if defined(BI_NAMESPACE)
  17. namespace OWL {
  18. #endif
  19.  
  20. // Generic definitions/compiler options (eg. alignment) preceeding the
  21. // definition of classes
  22. #include <services/preclass.h>
  23.  
  24. //
  25. // class TButton
  26. // ~~~~~ ~~~~~~~
  27. class _OWLCLASS TButton : public TControl {
  28.   public:
  29. #if defined(BI_PLAT_WIN32)
  30.     //For use with SetImage method.
  31.     enum TImageType { Bitmap=IMAGE_BITMAP, Icon=IMAGE_ICON };
  32. #endif
  33.  
  34.     TButton(TWindow*        parent,
  35.             int             id,
  36.             const char far* text,
  37.             int X, int Y, int W, int H,
  38.             bool            isDefault = false,
  39.             TModule*        module = 0);
  40.  
  41.     TButton(TWindow* parent, int resourceId, TModule* module = 0);
  42.    ~TButton();
  43.  
  44.     bool  GetIsDefPB() const;
  45.     void  SetIsDefPB(bool isdefpb);
  46.  
  47.     bool  GetIsCurrentDefPB() const;
  48.     void  SetIsCurrentDefPB(bool is);
  49.  
  50.     uint  GetState() const;
  51.     void  SetState(uint state);
  52.  
  53.     void  SetStyle(uint style, bool redraw);
  54.  
  55. #if defined(BI_PLAT_WIN32)
  56.     void   Click();
  57.  
  58.     // image can be HICON or HBITMAP
  59.     //
  60.     HANDLE GetImage() const;
  61.     HANDLE SetImage(HANDLE image, TImageType imageType = Bitmap);
  62. #endif
  63.  
  64.   protected:
  65.     // Message response functions
  66.     //
  67.     uint      EvGetDlgCode(MSG far*);
  68.     TResult   BMSetStyle(TParam1, TParam2);
  69.  
  70.     // Override TWindow member functions
  71.     //
  72.     char far* GetClassName();
  73.     void      SetupWindow();
  74.  
  75.   public_data:
  76.     bool  IsDefPB;
  77.  
  78.   protected_data:
  79.     bool  IsCurrentDefPB;
  80.  
  81.   private:
  82.     // Hidden to prevent accidental copying or assignment
  83.     //
  84.     TButton(const TButton&);
  85.     TButton& operator=(const TButton&);
  86.  
  87.   DECLARE_RESPONSE_TABLE(TButton);
  88.   DECLARE_STREAMABLE(_OWLCLASS, TButton, 1);
  89. };
  90.  
  91. // Generic definitions/compiler options (eg. alignment) following the
  92. // definition of classes
  93. #include <services/posclass.h>
  94.  
  95. //
  96. // button notification response table entry macros, methods are: void method()
  97. //
  98. // EV_BN_CLICKED(id, method)
  99. // EV_BN_DISABLE(id, method)
  100. // EV_BN_DOUBLECLICKED(id, method)
  101. // EV_BN_HILITE(id, method)
  102. // EV_BN_PAINT(id, method)
  103. // EV_BN_UNHILITE(id, method)
  104.  
  105. #if defined(BI_NAMESPACE)
  106. } // namespace OWL
  107. #endif
  108.  
  109. //----------------------------------------------------------------------------
  110. // Inline implementations
  111. //
  112.  
  113. //
  114. // Return true if this button is the default pushbutton.
  115. //
  116. inline bool TButton::GetIsDefPB() const
  117. {
  118.   return IsDefPB;
  119. }
  120.  
  121. //
  122. // Set this button the default pushbutton.
  123. //
  124. inline void TButton::SetIsDefPB(bool isdefpb)
  125. {
  126.   IsDefPB = isdefpb;
  127. }
  128.  
  129. //
  130. // Return true if this button is the current default pushbutton.
  131. //
  132. inline bool TButton::GetIsCurrentDefPB() const
  133. {
  134.   return IsCurrentDefPB;
  135. }
  136.  
  137. //
  138. // Set this button the current default push button.
  139. //
  140. inline void TButton::SetIsCurrentDefPB(bool is)
  141. {
  142.   IsCurrentDefPB = is;
  143. }
  144.  
  145. #if defined(BI_PLAT_WIN32)
  146. //
  147. // Simulate clicking of this button
  148. //
  149. inline void TButton::Click()
  150. {
  151.   PRECONDITION(GetHandle());
  152.   SendMessage(BM_CLICK);
  153. }
  154.  
  155. //
  156. // Return the image associated with the button.
  157. //
  158. inline HANDLE TButton::GetImage() const
  159. {
  160.   PRECONDITION(GetHandle());
  161.   return (HANDLE)CONST_CAST(TButton*, this)->SendMessage(BM_GETIMAGE);
  162. }
  163.  
  164. //
  165. // Set the associated image for this button.
  166. //
  167. inline HANDLE TButton::SetImage(HANDLE newImage, TImageType imageType)
  168. {
  169.   PRECONDITION(GetHandle());
  170.   return (HANDLE)SendMessage(BM_SETIMAGE, (TParam1)imageType, (TParam2)newImage);
  171. }
  172. #endif
  173.  
  174. //
  175. // Set the display state of the button.
  176. //
  177. inline void TButton::SetState(uint state)
  178. {
  179.   PRECONDITION(GetHandle());
  180.   SendMessage(BM_SETSTATE, state);
  181. }
  182.  
  183. //
  184. //
  185. inline uint TButton::GetState() const
  186. {
  187.   PRECONDITION(GetHandle());
  188.   return (uint)CONST_CAST(TButton*, this)->SendMessage(BM_GETSTATE);
  189. }
  190.  
  191. //
  192. inline void TButton::SetStyle(uint style, bool redraw)
  193. {
  194.   PRECONDITION(GetHandle());
  195.   SendMessage(BM_SETSTYLE, style, MkParam2(redraw,0));
  196. }
  197.  
  198. #endif  // OWL_BUTTON_H
  199.